package com.haois.ws.common.exception;


import com.haois.ws.common.constant.Reply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 处理controller异常
 *
 */
@ControllerAdvice
public class ErrorHandlerController {

	private static final Logger logger = LoggerFactory
			.getLogger(ErrorHandlerController.class);


	@ResponseBody
	@ExceptionHandler(ErrorException.class)
	public String  errorException(ErrorException exception) {
		logger.debug("ErrorException:{}:{}",exception.getErrorCode(), exception.getMessage());
		return new Reply(exception.getErrorCode(),exception.getMessage()).toJson();

	}

	@ResponseBody
	@ExceptionHandler(Exception.class)
	public String exception(Exception exception) {
		exception.printStackTrace();
		logger.debug("Exception:{}", exception.getMessage());
		return new Reply("10",""+"【"+exception.getMessage()+"】").toJson();

	}


}
